package android.calculadora;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Calculadora extends Activity {
	
	private EditText campoEuros;
    private EditText campoPesetas;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        campoEuros = (EditText) findViewById(R.id.euros);
        campoPesetas = (EditText) findViewById(R.id.pesetas);
        
        Button eurosAPesetas = (Button) findViewById(R.id.euros2pesetas);
        Button pesetasAEuros = (Button) findViewById(R.id.pesetas2euros);
        Button limpiar = (Button) findViewById(R.id.limpiar);
        Button salir = (Button) findViewById(R.id.salir);
        
        Button g3g = (Button) findViewById(R.id.g3g);
        
        eurosAPesetas.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	campoPesetas.setText(""+Double.parseDouble(campoEuros.getText().toString())*166.386);
            }
        });
        pesetasAEuros.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	campoEuros.setText(""+Double.parseDouble(campoPesetas.getText().toString())/166.386);
            }
        });
        
        limpiar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	campoEuros.setText("");
            	campoPesetas.setText("");
            }
        });
        
        salir.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	setResult(RESULT_OK);
                finish();
            }
        });
        
        g3g.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	
            	Intent i = new Intent("android.intent.action.VIEW");
                i.setAction("com.android.phone");
                ComponentName c = new ComponentName("com.android.phone", "com.android.phone.Settings");
                i.setComponent(c);
                startActivity(i);

        		//finish();
            	
            }
        });
        
        
    }
}